home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / monitory / asktask / at_putdata.c < prev    next >
C/C++ Source or Header  |  1989-07-22  |  11KB  |  265 lines

  1. /* at_putdata.c */
  2. /*************************************************************************
  3.  ***                    AskTask PutData Module                         ***
  4.  *** Date begun: 2/4/89.                                               ***
  5.  *** Last modified: 2/4/89.                                            ***
  6.  *************************************************************************/
  7. /*** This contains supplementary display functions cut from asktask.c  ***
  8.  *************************************************************************/
  9.  
  10. #include "asktask.h"
  11.  
  12. extern struct Window    *Window;
  13. extern struct Task  *task[NUM_TASKS];
  14. extern char         tnames[NUM_TASKS*TNAMESIZE];
  15. extern char         *tnp[NUM_TASKS];
  16. extern int          numtasks,page,ct;
  17.  
  18. extern void input(struct Window *,char *,char *,char *,int,int,int,int,int);
  19.  
  20. char    thbuf[21];
  21. char    tlbuf[21];
  22. struct IntuiText    taskhead = {1,0,JAM2,4,11,NULL,&thbuf[0],NULL};
  23. struct IntuiText    taskline = {3,0,JAM1,0,0,NULL,&tlbuf[0],NULL};
  24. char    dhbuf[51];
  25. struct IntuiText    datatask = {3,2,JAM1,218,11,NULL,&dhbuf[0],NULL};
  26. struct IntuiText    datahead = {1,2,JAM1,170,11,NULL,"Task: ",&datatask};
  27.  
  28. struct IntuiText    msgline = {1,2,JAM1,4,135,NULL,NULL,NULL};
  29. struct IntuiText    notask = {0,3,JAM1,0,0,NULL,"No current task",NULL};
  30.  
  31. struct IntuiText    datafixd = {1,2,JAM1,170,105,NULL,"E:",NULL};
  32. struct IntuiText    datafixc = {1,2,JAM1,170,97,NULL,"R:",&datafixd};
  33. struct IntuiText    datafixb = {1,2,JAM1,170,89,NULL,"W:",&datafixc};
  34. struct IntuiText    datafixa = {1,2,JAM1,170,81,NULL,"A:",&datafixb};
  35. struct IntuiText    datafix9 = {1,2,JAM1,220,71,NULL,"Signals",&datafixa};
  36. struct IntuiText    datafix8 = {1,2,JAM1,358,65,NULL,"Rm",&datafix9};
  37. struct IntuiText    datafix7 = {1,2,JAM1,358,57,NULL,"Sz",&datafix8};
  38. struct IntuiText    datafix6 = {1,2,JAM1,358,49,NULL,"Up",&datafix7};
  39. struct IntuiText    datafix5 = {1,2,JAM1,358,41,NULL,"Lw",&datafix6};
  40. struct IntuiText    datafix4 = {1,2,JAM1,358,33,NULL,"Rg",&datafix5};
  41. struct IntuiText    datafix3 = {1,2,JAM1,386,23,NULL,"Stack",&datafix4};
  42. struct IntuiText    datafix2 = {1,2,JAM1,170,39,NULL,"Flag:",&datafix3};
  43. struct IntuiText    datafix1 = {1,2,JAM1,170,31,NULL,"State:",&datafix2};
  44. struct IntuiText    datafix = {1,2,JAM1,170,23,NULL,"Priority:",&datafix1};
  45. char    dvbuf[41];
  46. struct IntuiText    datavar = {0,2,JAM1,0,0,NULL,&dvbuf[0],NULL};
  47.  
  48. char    *anon = "---- Anonymous ----";
  49. char    *state[8] = {
  50.     "TS_INVALID",   "TS_ADDED",     "TS_RUN",       "TS_READY",
  51.     "TS_WAIT",      "TS_EXCEPT",    "TS_REMOVED",   "BEYOND ME!"};
  52. char    *flag[9] = {
  53.     "TB_PROCTIME",  "NOTHING",      "NOTHING",      "NOTHING",
  54.     "TB_STACKCHK",  "TB_EXCEPT",    "TB_SWITCH",    "TB_LAUNCH",
  55.     "BEYOND ME!"};
  56.  
  57. unsigned long bitsput(char *);          /* Convert bit string to ULONG */
  58. void    putbits(char *,unsigned long);  /* Convert ULONG to bit string */
  59. void    prevpage();                     /* Previous task page */
  60. void    nextpage();                     /* Next task page */
  61. void    puttname(int,int);              /* Put task name n at line y */
  62. void    puttasks();                     /* Display current task page */
  63. void    puttaskdata();                  /* Display current task's data */
  64. void    setupwindow();                  /* Draws boxes and things */
  65. void    putmessage(char *,int);         /* Display a message line */
  66. char    getchfromw();                   /* Get a character from Window */
  67. int     yesno();                        /* Return user's yes or no */
  68.  
  69. unsigned long bitsput(cp) /*=============================================*/
  70. char    *cp;              /* Converts bit string cp to unsigned long. If */
  71. {                         /* string is too small, the missing bits are   */
  72. unsigned long   r;        /* left as zero.                               */
  73. int     i;
  74.     r = 0;  i = 31;
  75.     while (*cp && (i > -1)) {
  76.         if (*cp == '1') r = r + (1L << i);
  77.         i--;    cp++;
  78.     }
  79.     return(r);
  80. }
  81.  
  82. void    putbits(cp,l) /*=================================================*/
  83. char    *cp;          /* Converts ULONG l into a 32-bit string cp. Uses  */
  84. unsigned long   l;    /* 33 characters including the zero string ender.  */
  85. {
  86. int     j;
  87.     for (j = 0; j < 32; j++) cp[j] = (l & (1L << (31-j))) ? '1':'0';
  88.     cp[32] = 0;
  89. }
  90.  
  91. void    prevpage() /*====================================================*/
  92. {                  /* Display previous task page.                        */
  93.     putmessage("",1);
  94.     if (page == 0) {
  95.         putmessage("There's no previous task page!",3);
  96.         return;
  97.     }
  98.     page--;
  99.     puttasks();
  100. }
  101.  
  102. void    nextpage() /*====================================================*/
  103. {                  /* Display next task page                             */
  104.     putmessage("",1);
  105.     if (numtasks <= (page + 1)*14) {
  106.         putmessage("There's no next task page!",3);
  107.         return;
  108.     }
  109.     page++;
  110.     puttasks();
  111. }
  112.  
  113. void    puttname(n,y) /*=================================================*/
  114. int     n,y;
  115. {
  116.     if (tnp[n][0]) sprintf(tlbuf,"%-.20s",tnp[n]);
  117.     else strcpy(tlbuf,anon);
  118.     PrintIText(Window->RPort,&taskline,4,21+y*8);
  119. }
  120.  
  121. void    puttasks() /*====================================================*/
  122. {                  /* Write the current page of task names */
  123. int     i,j;
  124.     putmessage("",1);
  125.     while (numtasks < page * 14) page--;
  126.     sprintf(thbuf," Task    (page %.1d/%.1d) ",1 + page,1 + (numtasks-1)/14);
  127.     PrintIText(Window->RPort,&taskhead,0,0);
  128.     SetAPen(Window->RPort,0);
  129.     RectFill(Window->RPort,4,21,165,132);
  130.     j = page * 14;  i = 0;
  131.     while ((j < numtasks) && (i < 14)) {
  132.         puttname(j,i);
  133.         i++; j++;
  134.     }
  135. }
  136.  
  137. void    puttaskdata() /*=================================================*/
  138. {                     /* Display the current task's data                 */
  139. int     s;
  140. long    stack[3];
  141. unsigned long   sigs[4];
  142.     putmessage("",1);
  143.     if (ct < 0) {
  144.         SetAPen(Window->RPort,1);
  145.         RectFill(Window->RPort,168,10,471,132);
  146.         SetAPen(Window->RPort,2);
  147.         RectFill(Window->RPort,176,14,463,128);
  148.         SetAPen(Window->RPort,3);
  149.         RectFill(Window->RPort,289,22,350,120);
  150.         RectFill(Window->RPort,229,52,410,80);
  151.         PrintIText(Window->RPort,¬ask,260,62);
  152.         return;
  153.     }
  154.     SetAPen(Window->RPort,2);
  155.     RectFill(Window->RPort,168,10,471,132);
  156.     SetAPen(Window->RPort,1);
  157.     Move(Window->RPort,170,19);     Draw(Window->RPort,469,19);
  158.     if (tnp[ct][0]) strcpy(dhbuf,tnp[ct]);
  159.     else strcpy(dhbuf,anon);
  160.     PrintIText(Window->RPort,&datahead,0,0);
  161.     PrintIText(Window->RPort,&datafix,0,0);
  162.     Move(Window->RPort,376,31);
  163.     Draw(Window->RPort,444,31); Draw(Window->RPort,444,73);
  164.     Draw(Window->RPort,376,73); Draw(Window->RPort,376,31);
  165.     Move(Window->RPort,375,31); Draw(Window->RPort,375,73);
  166.     Move(Window->RPort,445,31); Draw(Window->RPort,445,73);
  167.     Move(Window->RPort,188,79);
  168.     Draw(Window->RPort,448,79);     Draw(Window->RPort,448,113);
  169.     Draw(Window->RPort,188,113);    Draw(Window->RPort,188,79);
  170.     Move(Window->RPort,187,79);     Draw(Window->RPort,187,113);
  171.     Move(Window->RPort,449,79);     Draw(Window->RPort,449,113);
  172.     s = (int)task[ct]->tc_Node.ln_Pri;
  173.     sprintf(dvbuf,"%3d",s); PrintIText(Window->RPort,&datavar,250,23);
  174.     s = (int)task[ct]->tc_State;
  175.     if ((s < 0) || (s > 7)) s = 7;
  176.     strcpy(dvbuf,state[s]); PrintIText(Window->RPort,&datavar,226,31);
  177.     s = (int)task[ct]->tc_Flags;
  178.     if ((s < 0) || ( s > 8)) s = 8;
  179.     strcpy(dvbuf,flag[s]); PrintIText(Window->RPort,&datavar,226,39);
  180.     SetAPen(Window->RPort,0);
  181.     RectFill(Window->RPort,377,32,443,72);
  182.     if (tnp[ct][0]) {
  183.         datavar.FrontPen = 2;
  184.         Disable();
  185.         stack[0] = (long)(task[ct]->tc_SPReg);
  186.         stack[1] = (long)(task[ct]->tc_SPLower);
  187.         stack[2] = (long)(task[ct]->tc_SPUpper);
  188.         Enable();
  189.         sprintf(dvbuf,"%08lx",stack[0]);
  190.         PrintIText(Window->RPort,&datavar,378,33);
  191.         sprintf(dvbuf,"%08lx",stack[1]);
  192.         PrintIText(Window->RPort,&datavar,378,41);
  193.         sprintf(dvbuf,"%08lx",stack[2]);
  194.         PrintIText(Window->RPort,&datavar,378,49);
  195.         sprintf(dvbuf,"%08lx",stack[2]-stack[1]);
  196.         PrintIText(Window->RPort,&datavar,378,57);
  197.         sprintf(dvbuf,"%08lx",stack[0]-stack[1]);
  198.         PrintIText(Window->RPort,&datavar,378,65);
  199.         datavar.FrontPen = 0;
  200.     }
  201.     Disable();
  202.     sigs[0] = task[ct]->tc_SigAlloc;    sigs[1] = task[ct]->tc_SigWait;
  203.     sigs[2] = task[ct]->tc_SigRecvd;    sigs[3] = task[ct]->tc_SigExcept;
  204.     Enable();
  205.     putbits(dvbuf,sigs[0]);     PrintIText(Window->RPort,&datavar,190,81);
  206.     putbits(dvbuf,sigs[1]);     PrintIText(Window->RPort,&datavar,190,89);
  207.     putbits(dvbuf,sigs[2]);     PrintIText(Window->RPort,&datavar,190,97);
  208.     putbits(dvbuf,sigs[3]);     PrintIText(Window->RPort,&datavar,190,105);
  209. }
  210.  
  211. void    setupwindow() /*=================================================*/
  212. {                     /* Draw boxes and things.                          */
  213.     SetAPen(Window->RPort,1);
  214.     Move(Window->RPort,166,10);     Draw(Window->RPort,166,132);
  215.     Move(Window->RPort,167,10);     Draw(Window->RPort,167,132);
  216.     Move(Window->RPort,472,10);     Draw(Window->RPort,472,132);
  217.     Move(Window->RPort,473,10);     Draw(Window->RPort,473,132);
  218.     PrintIText(Window->RPort,&taskhead,0,0);
  219.     Move(Window->RPort,4,19);       Draw(Window->RPort,163,19);
  220.     Move(Window->RPort,2,133);      Draw(Window->RPort,637,133);
  221.     SetAPen(Window->RPort,2);
  222.     RectFill(Window->RPort,2,134,636,143);
  223. }
  224.  
  225. void    putmessage(cp,c) /*==============================================*/
  226. char    *cp;             /* Display a message line cp, in color c.       */
  227. int     c;
  228. {
  229.     SetAPen(Window->RPort,2);
  230.     RectFill(Window->RPort,4,135,636,142);
  231.     msgline.IText = cp;
  232.     msgline.FrontPen = (UBYTE)c;
  233.     PrintIText(Window->RPort,&msgline,0,0);
  234. }
  235.  
  236. char    getchfromw() /*==================================================*/
  237. {                    /* Return a character from the Window.              */
  238. struct IntuiMessage *msg;
  239. int     loop;
  240. char    ch;
  241.     loop = 1;
  242.     while (loop) {
  243.         Wait(1<<Window->UserPort->mp_SigBit);
  244.         while (msg = (struct IntuiMessage *)GetMsg(Window->UserPort)) {
  245.             if (msg->Class != RAWKEY) {
  246.                 ReplyMsg((struct Message *)msg);
  247.                 continue;
  248.             }
  249.             ch = (char)msg->Code;   loop = 0;
  250.             ReplyMsg((struct Message *)msg);
  251.         }
  252.     }
  253.     return(ch);
  254. }
  255.  
  256. int     yesno() /*=======================================================*/
  257. {               /* Get a y/n answer from the window.                     */
  258. char    ch;
  259.     while (1) {
  260.         ch = getchfromw();
  261.         if ((ch == 0x15)||(ch == 0x36)||(ch == 0x45)) break;
  262.     }
  263.     return((ch == 0x15)? 1:0);
  264. }
  265.